package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.db.domain.Category;
import com.mall.db.domain.Search;
import com.mall.db.service.CategoryService;
import com.mall.db.service.SearchService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/system/search")
public class SearchController extends BaseController<Search>{
    @Resource(name = "searchService")
    private SearchService ss;
    @Resource(name = "categoryService")
    private CategoryService cs;

    @Override
    public Map<String, Object> find(Search search) {

        PageHelper.startPage(search.getPage(),search.getLimit());

        QueryWrapper<Search> qw = new QueryWrapper<>();

        List<Search> list = ss.list(qw);//搜索全部
        for (int i = 0; i < list.size() ; i++){
            Category category = cs.getById(list.get(0).getCid());
            list.get(i).setCategoryName(category.getName());
        }


        PageInfo<Search> page = new PageInfo<>(list,search.getLimit());

        return findMap(page.getList(),page.getTotal());
    }


}
